package com.sfang.common.util.string;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class RegexUtil {

    /**
     * 判断是否手机号
     *
     * @param phone
     * @return
     */
    public static boolean isMobilePhone(String phone) {
        boolean flag = true;
        String regex = "^\\d{1,50}$";

        Pattern p = Pattern.compile(regex);
        Matcher m = p.matcher(phone);
        flag = m.matches();

        return flag;
    }

    public static boolean isEmail(String string) {
        if (string == null)
            return false;
        String regEx1 = "^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";
        Pattern p;
        Matcher m;
        p = Pattern.compile(regEx1);
        m = p.matcher(string);
        if (m.matches())
            return true;
        else
            return false;
    }


    public static boolean machPWD(String password) {
        if (password == null)
            return false;
        if (password.length() < 6 || password.length() > 20)
            return false;
        // 必填字母数字特殊字符
        String reg = "[^\\s]{6,20}$";
        Pattern p;
        Matcher m;
        p = Pattern.compile(reg);
        m = p.matcher(password);
        if (m.matches())
            return true;
        else
            return false;

    }

    public static void main(String[] args) {
        System.out.println(machPWD("123"));
        System.out.println(machPWD("123@@"));
        System.out.println(machPWD("zzzzzzzzzzz"));
        System.out.println(machPWD("zzzzzzzz@@zzz"));
        System.out.println(machPWD("sss123"));
        System.out.println(machPWD("sgg123..!*.^&*()"));
        System.out.println(machPWD("sgg@123"));
        System.out.println(machPWD("sgg@."));
    }

}
